﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LingDong.IndexEntities.Document;
using LingDong.ConfigProvider;

namespace LingDong.QueryCore
{
    public class QueryResultEntity
    {
        public QueryResultEntity(ParsedDocumentEntity doc)
        {
            this.DocID = doc.DocID;
            this.Rank = doc.Rank;
            this.URL = doc.URL;
            if (!String.IsNullOrEmpty(doc.Title) &&
                doc.Title.Length > QueryResultEntity.maxTitleLength)
            {
                this.Title = doc.Title.Substring(0, QueryResultEntity.maxTitleLength) + " ...";
            }
            else
            {
                this.Title = doc.Title;
            }
        }

        public override string ToString()
        {
            return String.Format("ID: {0}, Rank: {1}, URL: {2}, Title: {3}, Abstract: {4}", 
                DocID, Rank, URL, Title, Abstract);
        }

        public int DocID { get; set; }
        public double Rank { get; set; }
        public string URL { get; set; }
        public string Title { get; set; }
        public string Abstract { get; set; }

        private static int maxTitleLength = ConfigQuery.Default.MaxTitleLength;
    }
}
